#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

int main()
{
    int n;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> pq;
    while (n--)
    {
        int tmp;
        cin >> tmp;
        pq.push(tmp);
    }
    int res = 0;
    while (pq.size() > 1)
    {
        int a = pq.top();
        pq.pop();
        int b = pq.top();
        pq.pop();
        pq.push(a + b);
        res += a + b;
    }
    cout << res << endl;
    return 0;
}